package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.CaseDataStatus;
import cn.fintecher.pangolin.entity.mysql.QCaseInfo;
import cn.fintecher.pangolin.service.business.model.BaseQueryRequest;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @Author wangxiangdong
 * @Description request
 * @Date 2019/8/30 17:01
 **/
@Data
public class OrganizationDistributeCaseRequest extends BaseQueryRequest {

    @ApiModelProperty("部门code")
    private String departCode;

    public BooleanBuilder generateQueryBuilder() {
        BooleanBuilder booleanBuilder = generateBaseQueryBuilder();
        QCaseInfo caseInfo = QCaseInfo.caseInfo;
        booleanBuilder.and(caseInfo.department.isNotNull()).and(caseInfo.currentCollector.isNull())
                .and(caseInfo.caseDataStatus.notIn(CaseDataStatus.PAUSE, CaseDataStatus.CIRCULATION, CaseDataStatus.SETTLT, CaseDataStatus.REDUCE).or(caseInfo.caseDataStatus.isNull()));
        if (Objects.nonNull(this.departCode)) {
            booleanBuilder.and(caseInfo.department.departCode.like(StringUtils.join(this.departCode, "%")));
        }
        return booleanBuilder;
    }
}
